{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d407a934-5ed7-4085-92b7-423018b5631d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "scalar_int= tf.Tensor(100, shape=(), dtype=int32)\n",
      "scalar_float= tf.Tensor(25.87, shape=(), dtype=float32)\n",
      "vector_int= tf.Tensor([10], shape=(1,), dtype=int32)\n",
      "vector_float= tf.Tensor([2.5 8.7], shape=(2,), dtype=float64)\n",
      "matrix_int= tf.Tensor(\n",
      "[[1 2 3]\n",
      " [4 5 6]], shape=(2, 3), dtype=int32)\n",
      "matrix_float= tf.Tensor(\n",
      "[[2.5 8. ]\n",
      " [1.8 3. ]\n",
      " [2.6 1.5]], shape=(3, 2), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "#例2-4\n",
    "import tensorflow as tf\n",
    "#创建并输出0维张量\n",
    "scalar_int=tf.constant(100)\n",
    "scalar_float=tf.constant(25.87)\n",
    "print(\"scalar_int=\",scalar_int)\n",
    "print(\"scalar_float=\",scalar_float)\n",
    "#创建并输出1维张量\n",
    "vector_int=tf.constant([10])\n",
    "vector_float=tf.constant([2.5,8.7],dtype=tf.float64)\n",
    "print(\"vector_int=\",vector_int)\n",
    "print(\"vector_float=\",vector_float)\n",
    "#创建并输出2维张量\n",
    "matrix_int=tf.constant([[1,2,3],[4,5,6]])\n",
    "matrix_float=tf.constant([[2.5,8.],[1.8,3.],[2.6,1.5]])\n",
    "print(\"matrix_int=\",matrix_int)\n",
    "print(\"matrix_float=\",matrix_float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7371a479-45f2-4123-b559-2ca77edba925",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}